package team.szm.scd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import team.szm.scd.database.mapper.DiseaseMapper;
import team.szm.scd.database.vo.DiseaseVO;
import team.szm.scd.service.interfaces.IDiseaseService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DiseaseServiceImpl implements IDiseaseService {
    @Resource
    DiseaseMapper mapper;

    @Override
    public List<DiseaseVO> diseaseLikeNameOrLikeInfo(String name) {
        QueryWrapper<DiseaseVO> wrapper = new QueryWrapper<>();
        wrapper.like("dsname", name).or();
        wrapper.like("dsinfo", name);
        return mapper.diseaseFromQueryWrapper(wrapper);
    }

    @Override
    public DiseaseVO diseaseFromId(Integer id) {
        QueryWrapper<DiseaseVO> wrapper = new QueryWrapper<>();
        wrapper.like("dsid", id);
        List<DiseaseVO> l = mapper.diseaseFromQueryWrapper(wrapper);
        if (l == null || l.isEmpty()) {
            return null;
        }
        return l.get(0);
    }
}
